package yhao.infra.service;

import org.apache.ibatis.session.Configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.Properties;

/**
 * @author yoara
 * <p> Created on 2019/8/12 </p>
 */
@ConfigurationProperties(prefix = YhaoInfraServiceProperties.PREFIX)
public class YhaoInfraServiceProperties {
    public static final String PREFIX = "yhao.infra.service";

    public static final String DRUID_STAT_SQL_LOG_PATH = PREFIX+".mybatis.druid-stat-sql-log-path";
    public static final String DEFAULT_AUTO_TX_NAME = PREFIX+".mybatis.default-auto-tx-name";

    /** mybatis相关配置 **/
    private Mybatis mybatis = new Mybatis();

    /** cache相关配置 **/
    private Cache cache = new Cache();

    public Mybatis getMybatis() {
        return mybatis;
    }

    public void setMybatis(Mybatis mybatis) {
        this.mybatis = mybatis;
    }

    public Cache getCache() {
        return cache;
    }

    public void setCache(Cache cache) {
        this.cache = cache;
    }

    public static class Mybatis {
        /**包名扫描，所有在该包下且继承了Entity的实体类可以自动别名化**/
        private String aliasesPackage;

        private String mapperLocation = "classpath*:mybatis/**/*.xml";

        /** 额外配置 **/
        private Properties configurationProperties;

        /** 自定义配置属性对象 **/
        @NestedConfigurationProperty
        private Configuration configuration;

        /** 输出sql日志，默认为true **/
        private boolean statSql = true;

        /**druid统计sql日志记录路径**/
        private String druidStatSqlLogPath;

        /**默认事务管理器名称**/
        private String defaultAutoTxName;

        public String getAliasesPackage() {
            return aliasesPackage;
        }

        public void setAliasesPackage(String aliasesPackage) {
            this.aliasesPackage = aliasesPackage;
        }

        public Properties getConfigurationProperties() {
            return configurationProperties;
        }

        public Mybatis setConfigurationProperties(Properties configurationProperties) {
            this.configurationProperties = configurationProperties;
            return this;
        }

        public Configuration getConfiguration() {
            return configuration;
        }

        public Mybatis setConfiguration(Configuration configuration) {
            this.configuration = configuration;
            return this;
        }

        public String getMapperLocation() {
            return mapperLocation;
        }

        public void setMapperLocation(String mapperLocation) {
            this.mapperLocation = mapperLocation;
        }

        public boolean isStatSql() {
            return statSql;
        }

        public void setStatSql(boolean statSql) {
            this.statSql = statSql;
        }

        public String getDruidStatSqlLogPath() {
            return druidStatSqlLogPath;
        }

        public Mybatis setDruidStatSqlLogPath(String druidStatSqlLogPath) {
            this.druidStatSqlLogPath = druidStatSqlLogPath;
            return this;
        }

        public String getDefaultAutoTxName() {
            return defaultAutoTxName;
        }

        public Mybatis setDefaultAutoTxName(String defaultAutoTxName) {
            this.defaultAutoTxName = defaultAutoTxName;
            return this;
        }
    }

    public static class Cache {
        /**数据缓存组件所用的cache BeanName，默认为系统cache**/
        private String dataCacheBeanName;

        public String getDataCacheBeanName() {
            return dataCacheBeanName;
        }

        public void setDataCacheBeanName(String dataCacheBeanName) {
            this.dataCacheBeanName = dataCacheBeanName;
        }
    }
}
